package com.stop.think.shiro.web.controller;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import com.stop.think.shiro.service.OrderRecordService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/pay")
public class PayPalController {

    @Resource private OrderRecordService orderRecordService;

    @GetMapping("/auth_url")
    public JSONObject createAuthUrl() {
        return orderRecordService.createPayOrder();
    }

    @GetMapping("/result")
    public JSONObject frontReturn(String token, String PayerID) {
        // 同步返回时
        boolean paySuccess = orderRecordService.payNotify(token, StrUtil.isBlank(PayerID));
        JSONObject retJson = new JSONObject();
        retJson.set("payResult", paySuccess);
        return retJson;
    }
}
